package com.example.springbootsecurity.service;

import com.example.springbootsecurity.entity.SysUser;
import com.example.springbootsecurity.responsitory.SysUserResponsitory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class CustomUserService implements UserDetailsService {

    @Autowired
    private SysUserResponsitory sysUserResponsitory;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = sysUserResponsitory.findByUsername(username);
        if (null == sysUser) {
            throw new RuntimeException("user is exists");
        }
        return sysUser;
    }
}
